package com.allen.flink.batch;

import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.tuple.Tuple2;

import java.util.ArrayList;

/**
 * 功能:数据合并
 *
 * @date: 2020-03-24 13:11
 * @author: Allen
 * @version: 0.0.4-snapshot
 * @Email: allenZyhang@163.com
 * @since: JDK 1.8
 **/
public class Union {
    
    public static void main(String[] args) throws Exception {
        //获取执行环境
        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        
       
        ArrayList<Tuple2<Integer,String>> list1=new ArrayList<>();
        list1.add(new Tuple2<>(101,"Mars"));
        list1.add(new Tuple2<>(102,"Tom"));
        list1.add(new Tuple2<>(103,"Alan"));
    
        ArrayList<Tuple2<Integer,String>> list2=new ArrayList<>();
        list2.add(new Tuple2<>(101,"Mark"));
        list2.add(new Tuple2<>(102,"Tom"));
        list2.add(new Tuple2<>(103,"Alex"));
        
      DataSet<Tuple2<Integer,String>> ds1= env.fromCollection(list1);
      DataSet<Tuple2<Integer,String>> ds2= env.fromCollection(list2);
      ds1.union(ds2).print();
    }
}
